<template>
  <div class="EntryFromEdit">
    <div class="form-title">
      <i class="el-icon-document"></i>
      <h4 class="form-title-text"></h4>
    </div>
      <div class="form-context">
        <el-form ref="form" :model="form.user" label-width="80px">

          <el-form-item label="用户名">
             <el-input v-model="form.user.username" style="width:50%"></el-input>
          </el-form-item>
          <el-form-item label="密码">
             <el-input v-model="form.user.password" auto-complete="off" type="password" style="width:50%"></el-input>
          </el-form-item>
          <el-form-item label="权限">
             <el-select v-model="form.user.auth" placeholder="-请选择-" style="width:50%">
                <el-option label="是" value="0"></el-option>
                <el-option label="否" value="1"></el-option>
             </el-select>
          </el-form-item>
          <!--<el-form-item label="是否锁定">
             <el-select v-model="form.user.islocking" placeholder="-请选择-" style="width:50%">
                <el-option label="是" value="0"></el-option>
                <el-option label="否" value="1"></el-option>
             </el-select>
          </el-form-item>-->
          <el-form-item>
            <el-button type="primary" @click="onSubmit">保存</el-button>
            <el-button @click="onCancel">取消</el-button>
          </el-form-item>
        </el-form>
      </div>
  </div>
</template>

<script>
import Qs from 'qs'
    export default {
        name: 'userEdit',
        data () {
            return {
            }
        },
      created(){
        this.$store.commit("update",[{name:'基础信息',router:'/'},{name:'用户管理',router:'/'}]);
      },
      methods:{
        onCancel(){
          this.$router.push({path:'UserForm',query:{activityId:this.$route.query.activityId,name:this.$route.query.name}});
        },
        onSubmit() {
            var url;
            if(this.form.user.id===''){
              this.form.user.id='0';
              url='/employee/save';
            }else{
              url='/employee/updateByid';
            }
            if(this.form.user.auth==undefined||this.form.user.auth==""){
              this.form.user.auth=1;
            }

            if(this.form.user.islocking==undefined||this.form.user.islocking==""){
              this.form.user.islocking=1;
            }
           var param=Qs.stringify({stock:JSON.stringify(this.form.user)});
          //this.$http.post(url,this.form.user)

          this.$axios.post(url,param,{headers:{'Content-Type':'application/x-www-form-urlencoded'}}).then(response => {
          if(response.data){
            this.$notify({
              title: '成功',
              message: '保存成功',
              type: 'success'
            });
            this.$router.push('/UserForm');
          }
          }, response => {
            this.$message('网络错误');
          });
        }
      },
      computed:{
          form:{
              get(){
                  return this.$store.state.user;
              },
            set(){

            }
          }
      }
    }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>

  .EntryFromEdit{
    width:100%;
    heigth:100%;
    background-color:#fff;
    border-radius: 2px;
    border:1px solid #E1E6EB;
  }
  .split{
    line-height:10px;
    height:10px;
  }
  .form-title{
    width:100%;
    height:50px;
    background:#F5F6FA;
    display: flex;
    justify-content: flex-start;
    align-items: center;
  }
  .el-icon-document{
    color:#2196F3;
    margin-left:24px;
    font-size:12px;
  }
  .form-title-text{
    font-family: "Adobe 宋体 Std L";
    margin-left: 17px;
  }
  .form-context{
    margin:36px 50px;
    width:700px;
  }

</style>
